add gdk_window_get_cursor()
authorCody Russell <bratsche@gnome.org>
Thu, 16 Jul 2009 06:16:01 +0000 (01:16 -0500)
committerCody Russell <bratsche@gnome.org>
Thu, 30 Jul 2009 03:38:36 +0000 (22:38 -0500)
gdk/gdkwindow.c
gdk/gdkwindow.h

index 754bf6e00f2416f08f7cecc65a405161f2445032..6db8cf17f0d5b2f6de4fef930a0d626bdb4f196f 100644 (file)
@@ -32,6 +32,7 @@
 #include "gdk.h"               /* For gdk_rectangle_union() */
 #include "gdkpixmap.h"
 #include "gdkdrawable.h"
+#include "gdkintl.h"
 #include "gdkscreen.h"
 #include "gdkmarshalers.h"
 #include "gdkalias.h"
@@ -128,6 +129,11 @@ enum {
   LAST_SIGNAL
 };
 
+enum {
+  PROP_0,
+  PROP_CURSOR
+};
+
 struct _GdkWindowPaint
 {
   GdkRegion *region;
@@ -293,6 +299,16 @@ static void gdk_window_free_paint_stack (GdkWindow *window);
 static void gdk_window_init       (GdkWindowObject      *window);
 static void gdk_window_class_init (GdkWindowObjectClass *klass);
 static void gdk_window_finalize   (GObject              *object);
+
+static void gdk_window_set_property (GObject      *object,
+                                     guint         prop_id,
+                                     const GValue *value,
+                                     GParamSpec   *pspec);
+static void gdk_window_get_property (GObject      *object,
+                                     guint         prop_id,
+                                     GValue       *value,
+                                     GParamSpec   *pspec);
+
 static void gdk_window_clear_backing_region (GdkWindow *window,
                                             GdkRegion *region);
 static void gdk_window_redirect_free      (GdkWindowRedirect *redirect);
@@ -410,6 +426,8 @@ gdk_window_class_init (GdkWindowObjectClass *klass)
   parent_class = g_type_class_peek_parent (klass);
 
   object_class->finalize = gdk_window_finalize;
+  object_class->set_property = gdk_window_set_property;
+  object_class->get_property = gdk_window_get_property;
 
   drawable_class->create_gc = gdk_window_create_gc;
   drawable_class->draw_rectangle = gdk_window_draw_rectangle;
@@ -444,6 +462,14 @@ gdk_window_class_init (GdkWindowObjectClass *klass)
   quark_pointer_window = g_quark_from_static_string ("gtk-pointer-window");
 
 
+  /* Properties */
+  g_object_class_install_property (object_class,
+                                   PROP_CURSOR,
+                                   g_param_spec_pointer ("cursor",
+                                                         P_("Cursor"),
+                                                         P_("Cursor"),
+                                                         G_PARAM_READWRITE));
+
   /**
    * GdkWindow::pick-embedded-child:
    * @window: the window on which the signal is emitted
@@ -568,6 +594,46 @@ gdk_window_finalize (GObject *object)
   G_OBJECT_CLASS (parent_class)->finalize (object);
 }
 
+static void
+gdk_window_set_property (GObject      *object,
+                         guint         prop_id,
+                         const GValue *value,
+                         GParamSpec   *pspec)
+{
+  GdkWindow *window = (GdkWindow *)object;
+
+  switch (prop_id)
+    {
+    case PROP_CURSOR:
+      gdk_window_set_cursor (window, g_value_get_pointer (value));
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+static void
+gdk_window_get_property (GObject    *object,
+                         guint       prop_id,
+                         GValue     *value,
+                         GParamSpec *pspec)
+{
+  GdkWindow *window = (GdkWindow *) object;
+
+  switch (prop_id)
+    {
+    case PROP_CURSOR:
+      g_value_set_pointer (value, gdk_window_get_cursor (window));
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
 static gboolean
 gdk_window_is_offscreen (GdkWindowObject *window)
 {
@@ -6947,6 +7013,30 @@ gdk_window_set_back_pixmap (GdkWindow *window,
     GDK_WINDOW_IMPL_GET_IFACE (private->impl)->set_back_pixmap (window, private->bg_pixmap);
 }
 
+/**
+ * gdk_window_get_cursor:
+ * @window: a #GdkWindow
+ * @cursor: a cursor
+ *
+ * Retrieves a #GdkCursor pointer for the cursor currently set on the
+ * specified #GdkWindow, or %NULL.  If the return value is %NULL then
+ * there is no custom cursor set on the specified window, and it is
+ * using the cursor for its parent window.
+ *
+ * Since: 2.18
+ */
+GdkCursor *
+gdk_window_get_cursor (GdkWindow *window)
+{
+  GdkWindowObject *private;
+
+  g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
+
+  private = (GdkWindowObject *) window;
+
+  return private->cursor;
+}
+
 /**
  * gdk_window_set_cursor:
  * @window: a #GdkWindow
@@ -6983,6 +7073,8 @@ gdk_window_set_cursor (GdkWindow *window,
 
       if (_gdk_window_event_parent_of (window, display->pointer_info.window_under_pointer))
        update_cursor (display);
+
+      g_object_notify (G_OBJECT (window), "cursor");
     }
 }
 
index a1d31849f3eddde1d6a37e0fbac7b70c02e21207..a3297d24ad7cf34cfe357afe49ae712ee5513c59 100644 (file)
@@ -517,6 +517,7 @@ void              gdk_window_set_back_pixmap (GdkWindow       *window,
                                          gboolean         parent_relative);
 void         gdk_window_set_cursor      (GdkWindow       *window,
                                          GdkCursor       *cursor);
+GdkCursor    *gdk_window_get_cursor      (GdkWindow       *window);
 void         gdk_window_get_user_data   (GdkWindow       *window,
                                          gpointer        *data);
 void         gdk_window_get_geometry    (GdkWindow       *window,